#include<bits/stdc++.h>//P15
using namespace std;
deque<int>dq;
int s[100005];
int main(){
    int n,m;scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",&s[i]);
    for(int i=1;i<=n;i++)s[i]=s[i]+s[i-1];//计算前缀和
    int ans=-1e8;
    dq.push_back(0);
    for(int i=1;i<=n;i++){
        while(!dq.empty()&&dq.front()<i-m)dq.pop_front();//队头超过m范围：删头
        if(dq.empty())ans=max(ans,s[i]);
        else ans=max(ans,s[i]-s[dq.front()]);//队头是最小的s[k]
        while(!dq.empty()&&s[dq.back()]>=s[i])dq.pop_back();//队尾大于s[i]，去尾
        dq.push_back(i);
    }
    printf("%d\n",ans);
    return 0;
}